/**
 * Created by Administrator on 2017/5/8.
 */
var mysql = require("mysql");

var MianMysql;

//链接数据库(第一步)
exports.open_db=myopen;
function myopen(){
    MianMysql = mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    })
}



/*===========================注册登录=========================================*/
/*=========================注册================================*/
exports.register_data=function(req,res,selecttxt,user,password,grade){
    var sql1=" SELECT * FROM users WHERE u_user=? and u_profession=?";
    var checking=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });
    checking.query(sql1,[user,selecttxt],function(err,data){
        if(err){

        }else{
            if(data==""){
                addtabel_lx(req,res,selecttxt,user,password,grade)
            }else{
                res.send("用户已经存在")
            }

        }
    })
};
function addtabel_lx(req,res,selecttxt,user,password,grade){
    var sql="insert into users (u_user,u_password,u_Grade,u_profession) VALUE (?,?,?,?)";
    var add_lx=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });
    add_lx.query(sql,[user,password,grade,selecttxt],function(err,data){
        if(err){

        }else{
            res.send("注册成功")
        }
    })

}
/*==================登录====================================*/
exports.login_data=function(req,res,selecttxt,user,password){
    var sql1="SELECT * FROM users WHERE u_user=? ";
    var checking=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });
    checking.query(sql1,[user],function(err,data){
        if(err){

        }else{
            if(data==""){
                res.send("用户不存在")
            }else{
                checked2(req,res,selecttxt,user,password)
            }

        }
    })
};
function checked2(req,res,selecttxt,user,password){
    var sql=" SELECT u_user,u_password,u_profession FROM users WHERE u_user=? and u_password=? and u_profession=?";
    var checked=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });
    checked.query(sql,[user,password,selecttxt],function(err,data){
        if(data){
            if(data==""){
                res.send("账号或密码或部门不正确")
            }else{
                checked1(req,res,selecttxt,user,password)
            }
        }else{


        }
    })
}
function checked1(req,res,selecttxt,user,password){
    var sql=" SELECT * FROM users WHERE u_user=? and  u_password =? and u_profession=?";
    var checked=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });
    checked.query(sql,[user,password,selecttxt],function(err,data){
        if(data){
            res.send("登录成功")
        }else{


        }
    })

}
/*========================修改密码================================================*/

exports.edit_data=function(req,res,editpass,usertext3,selecttext3){
    var sql1="SELECT * FROM users WHERE u_user=? and u_profession=?";
    var checking=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });
    checking.query(sql1,[usertext3,selecttext3],function(err,data){
        if(err){

        }else{
            if(data==""){
                res.send("用户不存在")
            }else{
                editpass1(req,res,editpass,usertext3,selecttext3)
            }

        }
    })
};
function editpass1(req,res,editpass,usertext3,selecttext3){
    var sql=" update users set u_password = ? where u_user = ? and u_profession=?";
    var checked=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });
    checked.query(sql,[editpass,usertext3,selecttext3],function(err,data){
        if(data){

            res.send("修改成功")
        }else{


        }
    })

}

/*============================客房管理==========================================*/
//客房预订添加
exports.routeTianjia =  function (user,tel,order_room,order_type,check_in,check_out,cash,room_cash,remark,order_time,re_status,res){
    var sql1= "INSERT INTO reserve (re_name,re_tel,re_ReserveTime,re_roomnuber,re_type,re_startTime,re_Endtime,re_deposit,re_roomRate,re_Remarks,re_status) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
    MianMysql.query(sql1,[user,tel,order_time,order_room,order_type,check_in,check_out,cash,room_cash,remark,re_status],function(error,data){
        if(error){

            res.end();
        }else{
            res.send("预定成功")

        }
    });
};

//预定表查询
exports.re_check_data=function(req,res){
    var sql1="SELECT re_name,re_startTime,re_EndTime,re_status,re_roomnuber FROM reserve ";
    MianMysql.query(sql1,[],function(error,data){
        if(error){

            res.end();
        }else{
            res.send(data);
        }
    });
}
exports.add_resver_data=function(req,res,num){
    var sql1="SELECT * FROM reserve where re_roomnuber=?";
    MianMysql.query(sql1,[num],function(error,data){
        if(error){
            res.end();
        }else{
            res.send(data);
        }
    });
}

exports.cancel_re_data=function(req,res,num,cancel_stau){
    var sql1="update reserve set re_status = ? where  re_roomnuber=?";
    MianMysql.query(sql1,[cancel_stau,num],function(error,data){
        if(error){

            res.end();
        }else{
            res.send(data);
        }
    });
}

exports.cancel_re_data_no=function(req,res,num){
    var sql=num
    MianMysql.query(sql,[],function(error,data){
        if(error){
            res.end();
        }else{
            res.send(data);

        }
    });
}


////客户查询
exports.routeselect = function(req,res,inp_1){
    var sql1="select * from accommodation where acc_number = ?";
    MianMysql.query(sql1,[inp_1],function(error,data){
        if(error){
            res.end();
        }else{
            res.json(data);
        }
    });
};
exports.routeselect123_1 = function(req,res,inp_1){
    var sql1="select * from accommodation where acc_name = ?";
    MianMysql.query(sql1,[inp_1],function(error,data){
        if(error){
            res.end();
        }else{
            res.json(data);
        }
    });
};


exports.cxnumber_lc=function(myid,res){
    var sql="select * from accommodation where acc_number=?";
    MianMysql.query(sql,[myid],function(error,data){
        if(error){

        }else{

            res.json(data);
        }
    })
}
exports.cxname_lc=function(myid,res){
    var sql="select * from accommodation where acc_name=?";
    MianMysql.query(sql,[myid],function(error,data){
        if(error){

        }else{

            res.json(data);
        }
    })
}
exports.lc_addmodify=function(val1,val3,val2,val5,val4,res){

    var sql="update accommodation set acc_type=?,acc_price=?,acc_number=?,p_cope=? where acc_name=?";
    MianMysql.query(sql,[val1,val3,val2,val5,val4],function(error,data){
        if(error){

        }else{
            res.json(data);
        }
    })
}
exports.lc_modifytime=function(val2,val1,res){
    var sql="update accommodation set acc_endtime=? where acc_name=?";
    MianMysql.query(sql,[val2,val1],function(error,data){
        if(error){

        }else{

            res.json(data);
        }
    })
}





//--------------退房-------------

//房间号查询退房
exports.chafan_table=function(chafan,res){
    var sql = "select * from accommodation where acc_number = ?";
    MianMysql.query(sql,[chafan],function(error,data){

        if(error){

            res.send("数据查询失败");
        }else{
            res.send(data);
        }
    })
};
//房间号查询退房
exports.chafan_table_wq=function(chafan,wq_status,room_xiaofei,res){
    var sql = "update accommodation set  acc_cons=? , acc_status=? where  acc_number=?";
    MianMysql.query(sql,[room_xiaofei,wq_status,chafan],function(error,data){
        if(error){
            res.send("数据查询失败");
        }else{
            res.send(data);
        }
    })

};
//名字查询退房
exports.chafan_table2=function(chafan2,res){
    var sql = "select * from accommodation where acc_name = ?";
    MianMysql.query(sql,[chafan2],function(error,data){
        if(error){
            res.send("数据查询失败");
        }else{

            res.send(data);
        }
    })
};







/*=====================住宿登记=================================*/
exports.routeText =  function (test1,test2,test3,test4,test5,test6,test7,test8,test9,test10,test11,test12,test13,test14,test15,test16,test17,acc_status,res){
    var sql1= "INSERT INTO accommodation (acc_name,acc_sex,acc_iddtype,acc_idcard,acc_deposit,acc_type,acc_price,acc_number,acc_startTime,acc_Endtime,acc_tel,p_Person,p_tel,p_cope,p_paid,p_Give,acc_clean,acc_status) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    MianMysql.query(sql1,[test1,test2,test3,test4,test5,test7,test6,test8,test9,test10,test11,test12,test13,test14,test15,test16,test17,acc_status],function(error,data){
        if(error){
            res.end();
        }else{
            res.json(data);
        }
    });
};
exports.re_check_zhusu_data=function(req,res){
    var sql1="SELECT acc_name,acc_startTime,acc_Endtime,acc_status,acc_number FROM accommodation ";
    MianMysql.query(sql1,[],function(error,data){
        if(error){
            res.end();
        }else{
            res.send(data);
        }
    });
}

exports.re_check_zhusuadd_data=function(num,req,res){
    var sql1="SELECT * FROM accommodation where acc_number=?";
    MianMysql.query(sql1,[num],function(error,data){
        if(error){
            res.end();
        }else{
            res.send(data);
        }
    });
};
exports.cancel_re_room_data=function(req,res,num,cancel_stau){
    var sql1="update accommodation set acc_status = ? where  acc_number=?";
    MianMysql.query(sql1,[cancel_stau,num],function(error,data){
        if(error){
            res.end();
        }else{
            res.send(data);
        }
    });
};

/*===========================客户信息==========================================*/

//查表
exports.information = function(req,res){
    var sql = "SELECT * from Accommodation";

    MianMysql.query(sql,[],function(error,data){
        if(error){
            res.send("数据查询失败");

        }else{
            res.send(data);
            res.end();

        }
    })

};

//删除信息
exports.Delete_table = delete_fun;

function delete_fun(shang,res){
    var sql = "DELETE from Accommodation WHERE id=?;";
    MianMysql.query(sql,[shang],function(error,data){
        if(error){

        }else{

            res.send(data);

        }
    });
}
//日期查找
exports.riqicha = riqicha_fun;

function riqicha_fun(kaishit,jieshu,res){
    var sql1="select * from Accommodation where acc_startTime BETWEEN ? and ?"

    MianMysql.query(sql1,[kaishit,jieshu],function(error,data){
        if(error){

            res.send("查询错误");
        }else{

            res.send(data);

        }
    })

}
//修改信息
//修改姓名
exports.xinmin_table = xinmin_fun;
function xinmin_fun(xinmin,num,res){
    var sql = "UPDATE accommodation set acc_name=? WHERE id =?";

    MianMysql.query(sql,[xinmin,num],function(error,data){

        if(error){

        }else{
            res.send(data);


        }
    });
}
//修改性别
exports.xinbie_table = xinbie_fun;
function xinbie_fun(xinbie,num,res){
    var sql = "UPDATE accommodation set acc_sex=? WHERE id =?";

    MianMysql.query(sql,[xinbie,num],function(error,data){

        if(error){

        }else{
            res.send(data);


        }
    });
}
//修改入住时间
exports.rzsj_table = rzsj_fun;
function rzsj_fun(rzsj,num,res){
    var sql = "UPDATE accommodation set acc_startTime=? WHERE id =?";

    MianMysql.query(sql,[rzsj,num],function(error,data){

        if(error){

        }else{
            res.send(data);


        }
    });
}
//修改退房时间
exports.tfsj_table = tfsj_fun;
function tfsj_fun(tfsj,num,res){
    var sql = "UPDATE accommodation set acc_Endtime=? WHERE id =?";

    MianMysql.query(sql,[tfsj,num],function(error,data){

        if(error){

        }else{
            res.send(data);


        }
    });
}
//修改证件号码
exports.zjhm_table = zjhm_fun;
function zjhm_fun(zjhm,num,res){
    var sql = "UPDATE accommodation set acc_idcard=? WHERE id =?";

    MianMysql.query(sql,[zjhm,num],function(error,data){

        if(error){

        }else{
            res.send(data);


        }
    });
}
//修改所住房间
exports.szfj_table = szfj_fun;
function szfj_fun(szfj,num,res){
    var sql = "UPDATE accommodation set acc_number=? WHERE id =?";

    MianMysql.query(sql,[szfj,num],function(error,data){

        if(error){

        }else{
            res.send(data);


        }
    });
}
//修改房间费
exports.xfje_table = xfje_fun;
function xfje_fun(xfje,num,res){
    var sql = "UPDATE accommodation set acc_price=? WHERE id =?";

    MianMysql.query(sql,[xfje,num],function(error,data){

        if(error){

        }else{
            res.send(data);


        }
    });
}
//修改消费金额
exports.xfjee_table = xfjee_fun;
function xfjee_fun(xfjee,num,res){
    var sql = "UPDATE accommodation set acc_cons=? WHERE id =?";

    MianMysql.query(sql,[xfjee,num],function(error,data){

        if(error){

        }else{
            res.send(data);


        }
    });
}


//修改所交押金
exports.sjyj_table = sjyj_fun;
function sjyj_fun(sjyj,num,res){
    var sql = "UPDATE accommodation set acc_deposit=? WHERE id =?";

    MianMysql.query(sql,[sjyj,num],function(error,data){

        if(error){

        }else{
            res.send(data);


        }
    });
}

//修改入住类型
exports.szlx_table = szlx_fun;
function szlx_fun(szlx,num,res){
    var sql = "UPDATE accommodation set acc_type=? WHERE id =?";

    MianMysql.query(sql,[szlx,num],function(error,data){

        if(error){

        }else{
            res.send(data);


        }
    });
}
//修改电话号码
exports.dhhm_table = dhhm_fun;
function dhhm_fun(dhhm,num,res){
    var sql = "UPDATE accommodation set acc_tel=? WHERE id =?";

    MianMysql.query(sql,[dhhm,num],function(error,data){

        if(error){

        }else{
            res.send(data);


        }
    });
}
//修改入住状态
exports.dhhmo_table = dhhmo_fun;
function dhhmo_fun(dhhmo,num,res){
    var sql = "UPDATE accommodation set acc_status=? WHERE id =?";

    MianMysql.query(sql,[dhhmo,num],function(error,data){

        if(error){

        }else{
            res.send(data);


        }
    });
}

//修改全部
exports.xiugaiPost_table = xiugaiPost_fun;
function xiugaiPost_fun(xinmin,xinbie,rzsj,tfsj,zjhm,szfj,xfje,sjyj,szlx,szlxo,dhhm,num,dhhmo,res){
    var sql = "UPDATE accommodation set acc_name=?,acc_sex =?,acc_startTime=?,acc_Endtime=?,acc_idcard=?,acc_number=?,acc_price=?,acc_deposit=?,acc_type=?,acc_cons=?,acc_tel=?,acc_status=? WHERE id =?";

    MianMysql.query(sql,[xinmin,xinbie,rzsj,tfsj,zjhm,szfj,xfje,sjyj,szlx,szlxo,dhhm,dhhmo,num],function(error,data){

        if(error){

        }else{
            res.send(data);


        }
    });
}
//模糊查询
//姓名
exports.chaxun_table=function(chaxun,res){
    var sql = "select * from accommodation where acc_name like ?";
    MianMysql.query(sql,[chaxun],function(error,data){

        if(error){

            res.send("数据查询失败");
        }else{

            res.send(data);
        }
    })
};










//==================================管理人员===========================
exports.p_addStaff_lc=function(a_name,a_position,a_tel,a_address,a_sex,a_starttime,a_money,a_state,a_bonus,a_attendance,res){
    //console.log('成功了')
    var sql="INSERT INTO administration (a_name,a_position,a_tel,a_address,a_sex,a_InTime,a_money,a_state,a_bonus,a_attendance) VALUES (?,?,?,?,?,?,?,?,?,?);";
    MianMysql.query(sql,[a_name,a_position,a_tel,a_address,a_sex,a_starttime,a_money,a_state,a_bonus,a_attendance],function(error,data){
        if(error){
            //console.log(error);
            res.send(error);
        }else{
            console.log('添加数据成功');
            res.send('添加数据成功');
        }
    });
}


//分页

exports.lc_page=function(page,res){
    //console.log('成功了')
    var sql="SELECT * from administration ORDER BY id desc limit ?,8 ;";
    MianMysql.query(sql,[page],function(error,data){
        if(error){
            //console.log(error);
            res.send(error);
        }else{
            //console.log('添加数据成功');
            if(data.length>0){
                res.send(data);
            }
        }
    });
}
//总页数
exports.lc_pagenum=function(req,res){
    //console.log('成功了')
    var sql="SELECT count(*) as totalPage from administration;";
    MianMysql.query(sql,[],function(error,data){
        if(error){
            //console.log(error);
            res.send(error);
        }else{
            console.log(data);
            res.send(data);
        }
    });
}

//查询信息
exports.lc_id=function(lc_id,res){
    //console.log('成功了')
    var sql="SELECT * from administration where id=?";
    MianMysql.query(sql,[lc_id,lc_id],function(error,data){
        if(error){
            console.log(error);
            res.send(error);
        }else{
            console.log(data);

            res.send(data);
        }
    });
}
exports.lc_id1=function(lc_id,lc_id1,res){

    var sql="SELECT * from administration,journal where administration.id=? and journal.j_number=?";
    MianMysql.query(sql,[lc_id,lc_id1],function(error,data){
        if(error){

            res.send(error);
        }else{

            res.send(data);
        }
    });
}
//工号查询
exports.lc_number1=function(lc_id,res){

    var sql="SELECT * from administration where id=?";
    MianMysql.query(sql,[lc_id],function(error,data){
        if(error){

            res.send(error);
        }else{

            res.send(data);
        }
    });
}
//姓名查询
exports.lc_name1=function(lc_id,res){

    var sql="SELECT * from administration where a_name like ?";
    MianMysql.query(sql,[lc_id],function(error,data){
        if(error){

            res.send(error);
        }else{
            res.send(data);
        }
    });
}

//修改信息
exports.p_modify_lc=function(a_name,a_position,a_tel,a_address,a_sex,a_starttime,a_money,a_bonus, a_state,
                             a_attendance,lc_id,res){
    var sql="UPDATE administration set a_name=?,a_position=?,a_tel=?,a_address=?,a_sex=?,a_InTime=?,a_money=?,a_bonus=?,a_state=?,a_attendance=? where id=?";


    MianMysql.query(sql,[a_name,a_position,a_tel,a_address,a_sex,a_starttime,a_money,a_bonus,a_state,
        a_attendance,lc_id],function(error,data) {

        if (error) {

            res.send(error);
        } else {

            res.send(data);
        }
    })
}









//==================================安保人员===========================
exports.s_addStaff_lc=function(a_name,a_position,a_tel,a_address,a_sex,a_starttime,a_money,a_state,a_bonus,a_attendance,res){
    //console.log('成功了')
    var sql="INSERT INTO security (s_name,s_position,s_tel,s_address,s_sex,s_InTime,s_money,s_state,s_bonus,s_attendance) VALUES (?,?,?,?,?,?,?,?,?,?);";
    MianMysql.query(sql,[a_name,a_position,a_tel,a_address,a_sex,a_starttime,a_money,a_state,a_bonus,a_attendance],function(error,data){
        if(error){
            //console.log(error);
            res.send(error);
        }else{
            console.log('添加数据成功');
            res.send('添加数据成功');
        }
    });
}


//分页

exports.lc_page_s=function(page,res){
    //console.log('成功了')
    var sql="SELECT * from security ORDER BY id desc limit ?,8 ;";
    MianMysql.query(sql,[page],function(error,data){
        if(error){
            //console.log(error);
            res.send(error);
        }else{
            //console.log('添加数据成功');
            if(data.length>0){
                res.send(data);
            }
        }
    });
}
//总页数
exports.lc_pagenum_s=function(req,res){
    //console.log('成功了')
    var sql="SELECT count(*) as totalPage from security;";
    MianMysql.query(sql,[],function(error,data){
        if(error){
            //console.log(error);
            res.send(error);
        }else{
            console.log(data);
            res.send(data);
        }
    });
}

//查询信息
exports.lc_id_s=function(lc_id,res){

    var sql="SELECT * from security where id=?";
    MianMysql.query(sql,[lc_id,lc_id],function(error,data){
        if(error){

            res.send(error);
        }else{

            res.send(data);
        }
    });
}
exports.lc_id1_s=function(lc_id,lc_id1,res){

    var sql="SELECT * from logistics,ch_record where logistics.id=? and ch_record.c_num=?";
    MianMysql.query(sql,[lc_id,lc_id1],function(error,data){
        if(error){

            res.send(error);
        }else{

            res.send(data);
        }
    });
}
//工号查询
exports.lc_number1_s=function(lc_id,res){
    //console.log('成功了')
    var sql="SELECT * from security where id=?";
    MianMysql.query(sql,[lc_id],function(error,data){
        if(error){
            console.log(error);
            res.send(error);
        }else{
            console.log(data);
            res.send(data);
        }
    });
}
//姓名查询
exports.lc_name1_s=function(lc_id,res){
    //console.log('成功了')
    var sql="SELECT * from security where a_name like ?";
    MianMysql.query(sql,[lc_id],function(error,data){
        if(error){
            console.log(error);
            res.send(error);
        }else{
            console.log(data);
            res.send(data);
        }
    });
}

//修改信息
exports.p_modify_lc_s=function(a_name,a_position,a_tel,a_address,a_sex,a_starttime,a_money,a_bonus, a_state,
                               a_attendance,lc_id,res){
    var sql="UPDATE security set s_name=?,s_position=?,s_tel=?,s_address=?,s_sex=?,s_InTime=?,s_money=?,s_bonus=?,s_state=?,s_attendance=? where id=?";


    MianMysql.query(sql,[a_name,a_position,a_tel,a_address,a_sex,a_starttime,a_money,a_bonus,a_state,
        a_attendance,lc_id],function(error,data) {

        if (error) {

            res.send(error);
        } else {

            res.send(data);
        }
    })
}













//==================================后勤人员===========================


exports.l_addStaff_lc=function(a_name,a_position,a_tel,a_address,a_sex,a_starttime,a_money,a_state,a_bonus,a_attendance,res){
    //console.log('成功了')
    var sql="INSERT INTO logistics (l_name,l_position,l_tel,l_address,l_sex,l_InTime,l_money,l_state,l_bonus,l_attendance) VALUES (?,?,?,?,?,?,?,?,?,?);";
    MianMysql.query(sql,[a_name,a_position,a_tel,a_address,a_sex,a_starttime,a_money,a_state,a_bonus,a_attendance],function(error,data){
        if(error){
            //console.log(error);
            res.send(error);
        }else{
            console.log('添加数据成功');
            res.send('添加数据成功');
        }
    });
}


//分页

exports.lc_page_l=function(page,res){
    //console.log('成功了')
    var sql="SELECT * from logistics ORDER BY id desc limit ?,8 ;";
    MianMysql.query(sql,[page],function(error,data){
        if(error){
            //console.log(error);
            res.send(error);
        }else{
            //console.log('添加数据成功');
            if(data.length>0){
                res.send(data);
            }
        }
    });
}
//总页数
exports.lc_pagenum_l=function(req,res){
    //console.log('成功了')
    var sql="SELECT count(*) as totalPage from logistics;";
    MianMysql.query(sql,[],function(error,data){
        if(error){
            //console.log(error);
            res.send(error);
        }else{
            console.log(data);
            res.send(data);
        }
    });
}

//查询信息
exports.lc_id_l=function(lc_id,res){
    //console.log('成功了')
    var sql="SELECT * from logistics where id=?";
    MianMysql.query(sql,[lc_id,lc_id],function(error,data){
        if(error){
            //console.log(error);
            res.send(error);
        }else{
            //console.log(data);
            res.send(data);
        }
    });
}
exports.lc_id1_l=function(lc_id,res){
    //console.log('成功了')
    var sql="SELECT * from ch_record where c_num=?";
    MianMysql.query(sql,[lc_id],function(error,data){
        if(error){
            //console.log(error);
            res.send(error);
        }else{
            //console.log(data);
            res.send(data);
        }
    });
}
//工号查询
exports.lc_number1_l=function(lc_id,res){
    //console.log('成功了')
    var sql="SELECT * from logistics where id=?";
    MianMysql.query(sql,[lc_id],function(error,data){
        if(error){
            //console.log(error);
            res.send(error);
        }else{
            //console.log(data);
            res.send(data);
        }
    });
}
//姓名查询
exports.lc_name1_l=function(lc_id,res){
    //console.log('成功了')
    var sql="SELECT * from logistics where a_name like ?";
    MianMysql.query(sql,[lc_id],function(error,data){
        if(error){
            console.log(error);
            res.send(error);
        }else{
            console.log(data);
            res.send(data);
        }
    });
}

//修改信息
exports.p_modify_lc_l=function(a_name,a_position,a_tel,a_address,a_sex,a_starttime,a_money,a_bonus, a_state,
                               a_attendance,lc_id,res){
    var sql="UPDATE logistics set l_name=?,l_position=?,l_tel=?,l_address=?,l_sex=?,l_InTime=?,l_money=?,l_bonus=?,l_state=?,l_attendance=? where id=?";

    //console.log(a_name);
    //console.log(sql);
    console.log(lc_id);
    MianMysql.query(sql,[a_name,a_position,a_tel,a_address,a_sex,a_starttime,a_money,a_bonus,a_state,
        a_attendance,lc_id],function(error,data) {
        //console.log(a_name);
        if (error) {
            console.log(error);
            res.send(error);
        } else {
            console.log(data);
            res.send(data);
        }
    })
}
//=============廖聪=================


//======================gl===========
//列表日志
exports.db_journal = jouRnal;
function jouRnal(page,res){
    page = (page-1)*5;
    var sql1= "select * from Journal where 1=1 order by id desc";
    MianMysql.query(sql1,[page],function(error,data){
        if(error){
            res.end();
        }else{
            res.json(data);
        }
    });
}
//按时间查询
exports.db_journal_1 = journal_1;
function journal_1(in_1,res){
    var sql1= "select * from Journal where j_time like ?";
    MianMysql.query(sql1,[in_1],function(error,data){
        //console.log([in_1]);
        if(error){
            //console.log(error);
        }else{
            res.json(data);
        }
    });
}
//按姓名查询
exports.db_journal_2 = journal_2;
function journal_2(in_2,res){
    var sql1= "select * from Journal where j_name like ?";
    MianMysql.query(sql1,[in_2],function(error,data){
        if(error){
            //console.log(error);
        }else{
            res.json(data);
        }
    });
}
//按工号查询
exports.db_journal_3 = journal_3;
function journal_3(in_3,res){
    var sql1= "select * from Journal where j_number like ?";
    MianMysql.query(sql1,[in_3],function(error,data){

        //console.log([in_3]);
        if(error){
            //console.log(error);
        }else{

            res.json(data);
        }
    });
}

//添加新信息
exports.db_addend1 = function(inpu_1,inpu_2,inpu_3,inpu_4,res){
    var sql = "insert into Journal (j_name,j_time,j_journal,j_number) values (?,?,?,?);"
    MianMysql.query(sql,[inpu_1,inpu_2,inpu_3,inpu_4], function (error,data) {
        if(error){
            //console.log(error);
            res.send("数据添加失败");
        }else{
            res.send("数据添加成功");
        }

    })
}




////修改信息 页面
////1.先显示信息
exports.db_modify1 = select_db_modify1;

function select_db_modify1(s_name,res){
    var sql = "select * from Journal where id = ? ;"
    MianMysql.query(sql,[s_name],function(error,data){
        if(error){
            console.log(error);
        }else{
            /*console.log(data);*/
            res.json(data);
        }
    });
}
//修改信息 页面
//2.点击确认按钮之后
exports.db_modify2 = select_db_modify2;
function select_db_modify2(inp_1,inp_2,inp_3,inp_4,s_name,res){

    var sql = "update Journal set  j_name=?,j_time=?,j_journal=?,j_number=? where id=?;"
    MianMysql.query(sql,[inp_1,inp_2,inp_3,inp_4,s_name],function(error,data){
        if(error){
            console.log(error);
        }else{
            /* console.log(data);*/
            res.json(data);
        }
    });
}
//删除信息
exports.db_delete1 = select_db_delete1;
function select_db_delete1(s_name,res){

    var sql = "delete from Journal where  id=?;"
    MianMysql.query(sql,[s_name],function(error,data){
        if(error){
            console.log(error);
        }else{
            /* console.log(data);*/
            res.json(data);
        }
    });
}


//总收入
exports.db_y_income =function (req,res){
    var sql1= "select (sum(p_paid)+sum(acc_cons)) as sums from accommodation";

    MianMysql.query(sql1,[],function(error,data){
        if(error){
            //console.log(error);
            res.end();
        }else{
            //console.log(data);
            res.json(data);
        }
    });
}
//1月月收入
exports.db_y_income1 =function (req,res){
    var sql1="select   (sum(p_paid)+sum(acc_cons)) as sums,acc_startTime from accommodation WHERE acc_startTime between '2017-01-01' and '2017-02-01'";
    MianMysql.query(sql1,[],function(error,data){
        if(error){
            //console.log(error);
            res.end();
        }else{
            //console.log(data);
            res.json(data);
        }
    });
}
//2月月收入
exports.db_y_income2 =function (req,res){
    var sql1="select   (sum(p_paid)+sum(acc_cons)) as sums,acc_startTime from accommodation WHERE acc_startTime between '2017-02-01' and '2017-03-01'";
    MianMysql.query(sql1,[],function(error,data){
        if(error){
            //console.log(error);
            res.end();
        }else{
            //console.log(data);
            res.json(data);
        }
    });
}
//3月月收入
exports.db_y_income3 =function (req,res){
    var sql1="select   (sum(p_paid)+sum(acc_cons)) as sums,acc_startTime from accommodation WHERE acc_startTime between '2017-03-01' and '2017-04-01'";
    MianMysql.query(sql1,[],function(error,data){
        if(error){
            //console.log(error);
            res.end();
        }else{
            //console.log(data);
            res.json(data);
        }
    });
}
//4月月收入
exports.db_y_income4 =function (req,res){
    var sql1="select   (sum(p_paid)+sum(acc_cons)) as sums,acc_startTime from accommodation WHERE acc_startTime between '2017-04-01' and '2017-05-01'";
    MianMysql.query(sql1,[],function(error,data){
        if(error){
            //console.log(error);
            res.end();
        }else{
            //console.log(data);
            res.json(data);
        }
    });
}
//5月月收入
exports.db_y_income5 =function (req,res){
    var sql1="select   (sum(p_paid)+sum(acc_cons)) as sums,acc_startTime from accommodation WHERE acc_startTime between '2017-05-01' and '2017-06-01'";
    MianMysql.query(sql1,[],function(error,data){
        if(error){
            //console.log(error);
            res.end();
        }else{
            //console.log(data);
            res.json(data);
        }
    });
}
//6月月收入
exports.db_y_income6 =function (req,res){
    var sql1="select   (sum(p_paid)+sum(acc_cons)) as sums,acc_startTime from accommodation WHERE acc_startTime between '2017-06-01' and '2017-07-01'";
    MianMysql.query(sql1,[],function(error,data){
        if(error){
            //console.log(error);
            res.end();
        }else{
            //console.log(data);
            res.json(data);
        }
    });
}
//7月月收入
exports.db_y_income7 =function (req,res){
    var sql1="select   (sum(p_paid)+sum(acc_cons)) as sums,acc_startTime from accommodation WHERE acc_startTime between '2017-07-01' and '2017-08-01'";
    MianMysql.query(sql1,[],function(error,data){
        if(error){
            //console.log(error);
            res.end();
        }else{
            //console.log(data);
            res.json(data);
        }
    });
}
//8月月收入
exports.db_y_income8 =function (req,res){
    var sql1="select   (sum(p_paid)+sum(acc_cons)) as sums,acc_startTime from accommodation WHERE acc_startTime between'2017-08-01' and '2017-09-01'";
    MianMysql.query(sql1,[],function(error,data){
        if(error){
            //console.log(error);
            res.end();
        }else{
            //console.log(data);
            res.json(data);
        }
    });
}
//9月月收入
exports.db_y_income9 =function (req,res){
    var sql1="select   (sum(p_paid)+sum(acc_cons)) as sums,acc_startTime from accommodation WHERE acc_startTime between '2017-09-01' and '2017-10-01'";
    MianMysql.query(sql1,[],function(error,data){
        if(error){
            //console.log(error);
            res.end();
        }else{
            //console.log(data);
            res.json(data);
        }
    });
}
//10月月收入
exports.db_y_income10 =function (req,res){
    var sql1="select   (sum(p_paid)+sum(acc_cons)) as sums,acc_startTime from accommodation WHERE acc_startTime between '2017-10-01' and '2017-11-01'";
    MianMysql.query(sql1,[],function(error,data){
        if(error){
            //console.log(error);
            res.end();
        }else{
            //console.log(data);
            res.json(data);
        }
    });
}
//11月月收入
exports.db_y_income11 =function (req,res){
    var sql1="select   (sum(p_paid)+sum(acc_cons)) as sums,acc_startTime from accommodation WHERE acc_startTime between '2017-11-01' and '2017-12-01'";
    MianMysql.query(sql1,[],function(error,data){
        if(error){
            //console.log(error);
            res.end();
        }else{
            //console.log(data);
            res.json(data);
        }
    });
}
//12月月收入
exports.db_y_income12 =function (req,res){
    var sql1="select   (sum(p_paid)+sum(acc_cons)) as sums,acc_startTime from accommodation WHERE acc_startTime between '2017-12-01' and '2018-01-01'";
    MianMysql.query(sql1,[],function(error,data){
        if(error){
            //console.log(error);
            res.end();
        }else{
            //console.log(data);
            res.json(data);
        }
    });
}


//总支出
exports.db_y_expenditure =function (req,res){
    //维修记录/清洁记录表
    var sql1= "select sum(ch_record.c_expenditure) as s1 from ch_record " +
        "UNION select sum(e_expense.e_money) as s1 from  e_expense " +
        "UNION select sum(administration.a_money)+sum(administration.a_bonus)  from  administration " +
        "UNION select sum(security.s_money)+sum(security.s_bonus)  from  security " +
        "UNION select sum(logistics.l_money)+sum(logistics.l_bonus)  from  logistics";

    MianMysql.query(sql1,[],function(error,data){
        if(error){
            res.end();
        }else{
            var su=0;
            for (var i=0 ;i<data.length;i++){
                su += data[i].s1
            }

            res.json(su);

        }
    });


}
//1月支出
exports.db_y_expenditure1 =function (req,res){


    //维修记录/清洁记录表
    var sql1= "select sum(ch_record.c_expenditure) as s1 from ch_record WHERE c_time between '2017-01-01' and '2017-02-01'" +
            //员工费用表
        "UNION select sum(e_expense.e_money) as s1 from  e_expense WHERE e_time between '2017-01-01' and '2017-02-01'" +
            //管理人员表
        "UNION select sum(administration.a_money)+sum(administration.a_bonus) as s1 from  administration WHERE a_InTime between '2017-01-01' and '2017-02-01'" +
            //安保人员表
        "UNION select sum(security.s_money)+sum(security.s_bonus) as s1 from  security WHERE s_InTime between '2017-01-01' and '2017-02-01'" +
            //后勤人员表
        "UNION select sum(logistics.l_money)+sum(logistics.l_bonus) as s1 from  logistics WHERE l_InTime between '2017-01-01' and '2017-02-01'"



    MianMysql.query(sql1,[],function(error,data){
        if(error){
            //console.log(error);
            res.end();
        }else{
            var su=0;
            for (var i=0 ;i<data.length;i++){
                su += data[i].s1
            }

            res.json(su);
        }
    });

}
//2月支出
exports.db_y_expenditure2 =function (req,res){


    //维修记录/清洁记录表
    var sql1= "select sum(ch_record.c_expenditure) as s1 from ch_record WHERE c_time between '2017-02-01' and '2017-03-01'" +
            //员工费用表
        "UNION select sum(e_expense.e_money) as s1 from  e_expense WHERE e_time between '2017-02-01' and '2017-03-01'" +
            //管理人员表
        "UNION select sum(administration.a_money)+sum(administration.a_bonus) as s1 from  administration WHERE a_InTime between '2017-02-01' and '2017-03-01'" +
            //安保人员表
        "UNION select sum(security.s_money)+sum(security.s_bonus) as s1 from  security WHERE s_InTime between '2017-02-01' and '2017-03-01'" +
            //后勤人员表
        "UNION select sum(logistics.l_money)+sum(logistics.l_bonus) as s1 from  logistics WHERE l_InTime between '2017-02-01' and '2017-03-01'"



    MianMysql.query(sql1,[],function(error,data){
        if(error){
            //console.log(error);
            res.end();
        }else{
            var su=0;
            for (var i=0 ;i<data.length;i++){
                su += data[i].s1
            }

            res.json(su);
        }
    });

}
//3月支出
exports.db_y_expenditure3 =function (req,res){


    //维修记录清洁记录表
    var sql1= "select sum(ch_record.c_expenditure) as s1 from ch_record WHERE c_time between '2017-03-01' and '2017-04-01'" +
            //员工费用表
        "UNION select sum(e_expense.e_money) as s1 from  e_expense WHERE e_time between '2017-03-01' and '2017-04-01'" +
            //管理人员表
        "UNION select sum(administration.a_money)+sum(administration.a_bonus) as s1 from  administration WHERE a_InTime between '2017-03-01' and '2017-04-01'" +
            //安保人员表
        "UNION select sum(security.s_money)+sum(security.s_bonus) as s1 from  security WHERE s_InTime between '2017-03-01' and '2017-04-01'" +
            //后勤人员表
        "UNION select sum(logistics.l_money)+sum(logistics.l_bonus) as s1 from  logistics WHERE l_InTime between '2017-03-01' and '2017-04-01'"



    MianMysql.query(sql1,[],function(error,data){
        if(error){
            //console.log(error);
            res.end();
        }else{
            var su=0;
            for (var i=0 ;i<data.length;i++){
                su += data[i].s1
            }

            res.json(su);
        }
    });

}
//4月支出
exports.db_y_expenditure4 =function (req,res){


    //维修记录/清洁记录表
    var sql1= "select sum(ch_record.c_expenditure) as s1 from ch_record WHERE c_time between '2017-04-01' and '2017-05-01'" +
            //员工费用表
        "UNION select sum(e_expense.e_money) as s1 from  e_expense WHERE e_time between '2017-04-01' and '2017-05-01'" +
            //管理人员表
        "UNION select sum(administration.a_money)+sum(administration.a_bonus) as s1 from  administration WHERE a_InTime between '2017-04-01' and '2017-05-01'" +
            //安保人员表
        "UNION select sum(security.s_money)+sum(security.s_bonus) as s1 from  security WHERE s_InTime between '2017-04-01' and '2017-05-01'" +
            //后勤人员表
        "UNION select sum(logistics.l_money)+sum(logistics.l_bonus) as s1 from  logistics WHERE l_InTime between '2017-04-01' and '2017-05-01'"



    MianMysql.query(sql1,[],function(error,data){
        if(error){
            //console.log(error);
            res.end();
        }else{
            var su=0;
            for (var i=0 ;i<data.length;i++){
                su += data[i].s1
            }

            res.json(su);
        }
    });

}
//5月支出
exports.db_y_expenditure5 =function (req,res){


    //维修记录/清洁记录表
    var sql1= "select sum(ch_record.c_expenditure) as s1 from ch_record WHERE c_time between '2017-05-01' and '2017-06-01'" +
            //员工费用表
        "UNION select sum(e_expense.e_money) as s1 from  e_expense WHERE e_time between '2017-05-01' and '2017-06-01'" +
            //管理人员表
        "UNION select sum(administration.a_money)+sum(administration.a_bonus) as s1 from  administration WHERE a_InTime between '2017-05-01' and '2017-06-01'" +
            //安保人员表
        "UNION select sum(security.s_money)+sum(security.s_bonus) as s1 from  security WHERE s_InTime between '2017-05-01' and '2017-06-01'" +
            //后勤人员表
        "UNION select sum(logistics.l_money)+sum(logistics.l_bonus) as s1 from  logistics WHERE l_InTime between '2017-05-01' and '2017-06-01'"



    MianMysql.query(sql1,[],function(error,data){
        if(error){
            //console.log(error);
            res.end();
        }else{
            var su=0;
            for (var i=0 ;i<data.length;i++){
                su += data[i].s1
            }

            res.json(su);
        }
    });

}
//6月支出
exports.db_y_expenditure6 =function (req,res){


    //维修记录/清洁记录表
    var sql1= "select sum(ch_record.c_expenditure) as s1 from ch_record WHERE c_time between '2017-06-01' and '2017-07-01'" +
            //员工费用表
        "UNION select sum(e_expense.e_money) as s1 from  e_expense WHERE e_time between '2017-06-01' and '2017-07-01'" +
            //管理人员表
        "UNION select sum(administration.a_money)+sum(administration.a_bonus) as s1 from  administration WHERE a_InTime between '2017-06-01' and '2017-07-01'" +
            //安保人员表
        "UNION select sum(security.s_money)+sum(security.s_bonus) as s1 from  security WHERE s_InTime between '2017-06-01' and '2017-07-01'" +
            //后勤人员表
        "UNION select sum(logistics.l_money)+sum(logistics.l_bonus) as s1 from  logistics WHERE l_InTime between '2017-06-01' and '2017-07-01'"



    MianMysql.query(sql1,[],function(error,data){
        if(error){

            res.end();
        }else{
            var su=0;
            for (var i=0 ;i<data.length;i++){
                su += data[i].s1
            }

            res.json(su);
        }
    });

}
//7月支出
exports.db_y_expenditure7 =function (req,res){


    //维修记录/清洁记录表
    var sql1= "select sum(ch_record.c_expenditure) as s1 from ch_record WHERE c_time between '2017-07-01' and '2017-08-01' UNION select sum(e_expense.e_money) as s1 from  e_expense WHERE e_time between '2017-07-01' and '2017-08-01' UNION select sum(administration.a_money)+sum(administration.a_bonus) as s1 from  administration WHERE a_InTime between '2017-07-01' and '2017-08-01' UNION select sum(security.s_money)+sum(security.s_bonus) as s1 from  security WHERE s_InTime between '2017-07-01' and '2017-08-01' UNION select sum(logistics.l_money)+sum(logistics.l_bonus) as s1 from  logistics WHERE l_InTime between '2017-07-01' and '2017-08-01'"

    MianMysql.query(sql1,[],function(error,data){
        if(error){

            res.end();
        }else{
            var su=0;
            for (var i=0 ;i<data.length;i++){
                su += data[i].s1
            }
            res.json(su);

        }
    });

}
//8月支出
exports.db_y_expenditure8 =function (req,res){


    //维修记录/清洁记录表
    var sql1= "select sum(ch_record.c_expenditure) as s1 from ch_record WHERE c_time  between '2017-08-01' and '2017-09-01'" +
            //员工费用表
        "UNION select sum(e_expense.e_money) as s1 from  e_expense WHERE e_time between '2017-08-01' and '2017-09-01'" +
            //管理人员表
        "UNION select sum(administration.a_money)+sum(administration.a_bonus) as s1 from  administration WHERE a_InTime between '2017-08-01' and '2017-09-01'" +
            //安保人员表
        "UNION select sum(security.s_money)+sum(security.s_bonus) as s1 from  security WHERE s_InTime between '2017-08-01' and '2017-09-01'" +
            //后勤人员表
        "UNION select sum(logistics.l_money)+sum(logistics.l_bonus) as s1 from  logistics WHERE l_InTime between '2017-08-01' and '2017-09-01'"



    MianMysql.query(sql1,[],function(error,data){
        if(error){

            res.end();
        }else{
            var su=0;
            for (var i=0 ;i<data.length;i++){
                su += data[i].s1
            }

            res.json(su);
        }
    });

}
//9月支出
exports.db_y_expenditure9 =function (req,res){


    //维修记录/清洁记录表
    var sql1= "select sum(ch_record.c_expenditure) as s1 from ch_record WHERE c_time between '2017-09-01' and '2017-10-01'" +
            //员工费用表
        "UNION select sum(e_expense.e_money) as s1 from  e_expense WHERE e_time between '2017-09-01' and '2017-10-01'" +
            //管理人员表
        "UNION select sum(administration.a_money)+sum(administration.a_bonus) as s1 from  administration WHERE a_InTime between '2017-09-01' and '2017-10-01'" +
            //安保人员表
        "UNION select sum(security.s_money)+sum(security.s_bonus) as s1 from  security WHERE s_InTime between '2017-09-01' and '2017-10-01'" +
            //后勤人员表
        "UNION select sum(logistics.l_money)+sum(logistics.l_bonus) as s1 from  logistics WHERE l_InTime between '2017-09-01' and '2017-10-01'"



    MianMysql.query(sql1,[],function(error,data){
        if(error){

            res.end();
        }else{
            var su=0;
            for (var i=0 ;i<data.length;i++){
                su += data[i].s1
            }

            res.json(su);
        }
    });

}
//10月支出
exports.db_y_expenditure10 =function (req,res){


    //维修记录/清洁记录表
    var sql1= "select sum(ch_record.c_expenditure) as s1 from ch_record WHERE c_time between '2017-10-01' and '2017-11-01'" +
            //员工费用表
        "UNION select sum(e_expense.e_money) as s1 from  e_expense WHERE e_time between '2017-10-01' and '2017-11-01'" +
            //管理人员表
        "UNION select sum(administration.a_money)+sum(administration.a_bonus) as s1 from  administration WHERE a_InTime between '2017-10-01' and '2017-11-01'" +
            //安保人员表
        "UNION select sum(security.s_money)+sum(security.s_bonus) as s1 from  security WHERE s_InTime between '2017-10-01' and '2017-11-01'" +
            //后勤人员表
        "UNION select sum(logistics.l_money)+sum(logistics.l_bonus) as s1 from  logistics WHERE l_InTime between '2017-10-01' and '2017-11-01'"



    MianMysql.query(sql1,[],function(error,data){
        if(error){

            res.end();
        }else{
            var su=0;
            for (var i=0 ;i<data.length;i++){
                su += data[i].s1
            }
            res.json(su);
        }
    });

}
//11月支出
exports.db_y_expenditure11 =function (req,res){


    //维修记录/清洁记录表
    var sql1= "select sum(ch_record.c_expenditure) as s1 from ch_record WHERE c_time between '2017-11-01' and '2017-12-01'" +
            //员工费用表
        "UNION select sum(e_expense.e_money) as s1 from  e_expense WHERE e_time between '2017-11-01' and '2017-12-01'" +
            //管理人员表
        "UNION select sum(administration.a_money)+sum(administration.a_bonus) as s1 from  administration WHERE a_InTime between '2017-11-01' and '2017-12-01'" +
            //安保人员表
        "UNION select sum(security.s_money)+sum(security.s_bonus) as s1 from  security WHERE s_InTime between '2017-11-01' and '2017-12-01'" +
            //后勤人员表
        "UNION select sum(logistics.l_money)+sum(logistics.l_bonus) as s1 from  logistics WHERE l_InTime between '2017-11-01' and '2017-12-01'"



    MianMysql.query(sql1,[],function(error,data){
        if(error){

            res.end();
        }else{
            var su=0;
            for (var i=0 ;i<data.length;i++){
                su += data[i].s1
            }
            res.json(su);
        }
    });

}
//12月支出
exports.db_y_expenditure12 =function (req,res){


    //维修记录/清洁记录表
    var sql1= "select sum(ch_record.c_expenditure) as s1 from ch_record WHERE c_time between '2017-12-01' and '2018-01-01'" +
            //员工费用表
        "UNION select sum(e_expense.e_money) as s1 from  e_expense WHERE e_time between '2017-12-01' and '2018-01-01'" +
            //管理人员表
        "UNION select sum(administration.a_money)+sum(administration.a_bonus) as s1 from  administration WHERE a_InTime between '2017-12-01' and '2018-01-01'" +
            //安保人员表
        "UNION select sum(security.s_money)+sum(security.s_bonus) as s1 from  security WHERE s_InTime between '2017-12-01' and '2018-01-01'" +
            //后勤人员表
        "UNION select sum(logistics.l_money)+sum(logistics.l_bonus) as s1 from  logistics WHERE l_InTime between '2017-12-01' and '2018-01-01'"



    MianMysql.query(sql1,[],function(error,data){
        if(error){

            res.end();
        }else{
            var su=0;
            for (var i=0 ;i<data.length;i++){
                su += data[i].s1
            }
            res.json(su);
        }
    });

}


//维修--------------------------CH-----------------------------
//加载维修员工信息 ----CH--------------
exports.jzszCh_db=function(req,res){
    var Mainmysql=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });
    var sql="SELECT*FROM logistics where l_position='修理工';";

    Mainmysql.query(sql,[],function(error,data){
        res.send(data);

    });

    Mainmysql.end();
};
//加载维修员工信息 ----CH--------------
//添加员工信息 ------------CH-----------------
exports.zjszCh_db=function(req,res){

    var Mainmysql=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });

    var sql="insert into logistics (l_position,l_name,l_tel,l_address,l_money,l_bonus,l_state,l_sex,l_InTime,l_Attendance) values ('修理工',?,?,?,?,?,?,?,?,?);";
    Mainmysql.query(sql,[req.body.p1,req.body.p2,req.body.p3,req.body.p4,req.body.p5,req.body.p6,req.body.p7,req.body.p8,req.body.p9],function(error,data){
        res.send(data);


    });

    Mainmysql.end();
};
//添加员工信息 ------------CH-----------------
//删除员工信息 ------------CH-----------------
exports.scszCh_db=function(req,res){
    var Mainmysql=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });
    var sql="delete from logistics where id=?;";
    Mainmysql.query(sql,[req.body.sc],function(error,data){
        res.send(data);

    });

    Mainmysql.end();
};
//删除员工信息 ------------CH-----------------
//修改员工信息 -------------------CH-----------------
exports.xgszCh_db=function(req,res){
    var Mainmysql=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });

    var sql=" update logistics set l_tel=?,l_address=?,l_money=?,l_bonus=?,l_state=?,l_Attendance=? where id= ?;";
    Mainmysql.query(sql,[req.body.x1,req.body.x2,req.body.x3,req.body.x4,req.body.x5,req.body.x6,req.body.x0],function(error,data){
        res.send(data);



    });

    Mainmysql.end();
};
//修改员工信息 -------------------CH-----------------
//维修状态加载----------------------CH----------------------
exports.wxszCh_db=function(req,res){
    var Mainmysql=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });
    var sql="SELECT*FROM r_record;";
    Mainmysql.query(sql,[],function(error,data){
        res.send(data);


    });

    Mainmysql.end();
};

//维修状态加载----------------------CH----------------------
//指派工作---------------------------------------------------------
exports.zpgzCh_db=function(req,res){
    var Mainmysql=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });

    var sql="insert into r_record (r_name,r_tel,r_itme,r_time,r_expenditure,r_num,r_num1) values (?,?,?,?,?,?,?);";
    Mainmysql.query(sql,[req.body.r1,req.body.r3,req.body.r4,req.body.r5,req.body.r6,req.body.r2,req.body.r7],function(error,data){
        res.send(data);



    });
    Mainmysql.end();
};

//指派工作---------------------------------------------------------
//维修状态删除-----------------------------------------------------
exports.scwiCh_db=function(req,res){
    var Mainmysql=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });
    var sql="delete from r_record where r_name=?;";
    Mainmysql.query(sql,[req.body.ss1],function(error,data){
        res.send(data);

    });

    Mainmysql.end();
};
//维修状态删除-----------------------------------------------------
//维修日志加载------------------------------------------------------
exports.wwwCh_db=function(req,res){
    var Mainmysql=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });
    var sql="SELECT*FROM r_record1;";
    Mainmysql.query(sql,[],function(error,data){
        res.send(data);


    });

    Mainmysql.end();
};

//维修日志加载------------------------------------------------------
//维修日志增加
exports.www1Ch_db=function(req,res){
    var Mainmysql=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });
    var sql="insert into r_record1 (r_name,r_num,r_tel,r_itme,r_time,r_state,r_expenditure,r_num1) values (?,?,?,?,?,?,?,?);";
    Mainmysql.query(sql,[req.body.ss1,req.body.ss2,req.body.ss3,req.body.ss4,req.body.ss5,req.body.ss6,req.body.ss7,req.body.ss51],function(error,data){
        res.send(data);
    });
    var sql1="insert into ch_record (c_name,c_num,c_tel,c_itme,c_time,c_state,c_expenditure,c_num1) values (?,?,?,?,?,?,?,?);";
    Mainmysql.query(sql1,[req.body.ss1,req.body.ss2,req.body.ss3,req.body.ss4,req.body.ss5,req.body.ss6,req.body.ss7,req.body.ss51,"修理工"],function(error,data){
        res.send(data);
    });

    Mainmysql.end();
};

//维修日志增加

exports.xsCh_db=function(req,res){
    var Mainmysql=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });
    var sql="select * from logistics where l_name = ?;";
    Mainmysql.query(sql,[req.body.op1],function(error,data){
        res.send(data);




    });

    Mainmysql.end();
};

//清洁--------------------------CH-----------------------------
//清洁加载
exports.jzszCh1_db=function(req,res){
    var Mainmysql=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });
    var sql="SELECT*FROM logistics where l_position='清洁工';";

    Mainmysql.query(sql,[],function(error,data){
        res.send(data);


    });

    Mainmysql.end();
};
//----------
//添加员工信息 ------------CH-----------------
exports.zjszCh1_db=function(req,res){
    var Mainmysql=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });

    var sql="insert into logistics (l_position,l_name,l_tel,l_address,l_money,l_bonus,l_state,l_sex,l_InTime,l_Attendance) values ('清洁工',?,?,?,?,?,?,?,?,?);";
    Mainmysql.query(sql,[req.body.p1,req.body.p2,req.body.p3,req.body.p4,req.body.p5,req.body.p6,req.body.p7,req.body.p8,req.body.p9],function(error,data){
        res.send(data);


    });

    Mainmysql.end();
};
//添加员工信息 ------------CH-----------------
//删除员工信息 ------------CH-----------------
exports.scszCh1_db=function(req,res){
    var Mainmysql=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });
    var sql="delete from logistics where id=?;";
    Mainmysql.query(sql,[req.body.sc],function(error,data){
        res.send(data);

    });

    Mainmysql.end();
};
//删除员工信息 ------------CH-----------------
//修改员工信息 -------------------CH-----------------
exports.xgszCh1_db=function(req,res){
    var Mainmysql=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });

    var sql=" update logistics set l_tel=?,l_address=?,l_money=?,l_bonus=?,l_state=?,l_Attendance=? where id= ?;";
    Mainmysql.query(sql,[req.body.x1,req.body.x2,req.body.x3,req.body.x4,req.body.x5,req.body.x6,req.body.x0],function(error,data){
        res.send(data);



    });

    Mainmysql.end();
};
//修改员工信息 -------------------CH-----------------
//清洁状态加载----------------------CH----------------------
exports.wxszCh1_db=function(req,res){
    var Mainmysql=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });
    var sql="SELECT*FROM c_record;";
    Mainmysql.query(sql,[],function(error,data){
        res.send(data);


    });

    Mainmysql.end();
};

//维修状态加载----------------------CH----------------------
//指派工作---------------------------------------------------------
exports.zpgzCh1_db=function(req,res){
    var Mainmysql=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });

    var sql="insert into c_record (c_name,c_tel,c_itme,c_time,c_expenditure,c_num,c_num1) values (?,?,?,?,?,?,?);";
    Mainmysql.query(sql,[req.body.r1,req.body.r3,req.body.r4,req.body.r5,req.body.r6,req.body.r2,req.body.r7],function(error,data){
        res.send(data);




    });
    Mainmysql.end();
};

//指派工作---------------------------------------------------------
//维修状态删除-----------------------------------------------------
exports.scwiCh1_db=function(req,res){
    var Mainmysql=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });
    var sql="delete from c_record where c_name=?;";
    Mainmysql.query(sql,[req.body.ss1],function(error,data){
        res.send(data);

    });

    Mainmysql.end();
};
//维修状态删除-----------------------------------------------------
//维修日志加载------------------------------------------------------
exports.wwwCh1_db=function(req,res){
    var Mainmysql=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });
    var sql="SELECT*FROM c_record1;";
    Mainmysql.query(sql,[],function(error,data){
        res.send(data);


    });

    Mainmysql.end();
};

//维修日志加载------------------------------------------------------
//维修日志增加
exports.www1Ch1_db=function(req,res){
    var Mainmysql=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });

    var sql="insert into c_record1 (c_name,c_num,c_tel,c_itme,c_time,c_state,c_expenditure,c_num1) values (?,?,?,?,?,?,?,?);";
    Mainmysql.query(sql,[req.body.ss1,req.body.ss2,req.body.ss3,req.body.ss4,req.body.ss5,req.body.ss6,req.body.ss7,req.body.ss51],function(error,data){
        res.send(data);
    });
    var sql1="insert into ch_record (c_name,c_num,c_tel,c_itme,c_time,c_state,c_expenditure,c_num1) values (?,?,?,?,?,?,?,?);";
    Mainmysql.query(sql1,[req.body.ss1,req.body.ss2,req.body.ss3,req.body.ss4,req.body.ss5,req.body.ss6,req.body.ss7,req.body.ss51,"清洁工"],function(error,data){
        res.send(data);
    });
    Mainmysql.end();
};

//维修日志增加

exports.xsCh1_db=function(req,res){
    var Mainmysql=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"test"
    });
    var sql="select * from logistics where l_name = ?;";
    Mainmysql.query(sql,[req.body.op1],function(error,data){
        res.send(data);




    });

    Mainmysql.end();
};
//================================================================================================













//关闭数据库 (第三步)
exports.end_db = myend;
function myend(){
    MianMysql.end();
}
